{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "tensorflow的本质：tensor + 计算图\n",
    "tensor：数据\n",
    "op：计算操作\n",
    "graphs：数据操作（数据+计算）\n",
    "session：封装了执行Operation对象的环境，并且计算Tensor对象\n",
    "'''\n",
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor(\"Const_1:0\", shape=(), dtype=int32)\n",
      "<tf.Variable 'var_1:0' shape=() dtype=int32_ref>\n"
     ]
    }
   ],
   "source": [
    "const = tf.constant(2,dtype=tf.int32)\n",
    "var = tf.Variable(10,name='var')\n",
    "print(const)\n",
    "print(var)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# sess = tf.Session()\n",
    "# print(sess.run(const))\n",
    "# # tf中变量使用之前应该初始化\n",
    "# init = tf.global_variables_initializer()\n",
    "# sess.run(init)\n",
    "# print(sess.run(var))\n",
    "# sess.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "# 另一种使用session的方法\n",
    "init = tf.global_variables_initializer()\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init)\n",
    "    print(sess.run(const))\n",
    "    print(sess.run(var))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
